<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="searchHistory.splice(0)">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon name="delete" v-else @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      v-for="(item, index) in searchHistory"
      :title="item"
      :key="index"
      @click="onHistoryClick(item,index)"
    >
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: "SearchHistory",
  components: {},
  props: {
    searchHistory: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isDeleteShow: false,
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    onHistoryClick(item,index){
      if(this.isDeleteShow){
        //删除点击的那一条数据
        this.searchHistory.splice(index,1)
      }else{
        // 搜索 把当前点击的记录 赋值给 父组件的searchText
        this.$emit('search',item)
      }
    }
  },
};
</script>

<style scoped lang="less"></style>
